import React, {PureComponent} from 'react';
import {Link} from 'umi';
import {Exception} from 'cn-lib-for-4';
import AuthService from '@/utils/AuthService';

export function withAuth({code, Component}) {
  const authService = new AuthService();
  // 通过打印authService，可以看出authService已被mock，只是这里checkAuth返回的是undefined
  console.log(authService);
  return class extends PureComponent {
    render() {
      const authResult = authService.checkAuth(code);
      let authSuccess = undefined === authResult ? true : authResult;
      return authSuccess ? (
        <Component {...this.props} />
      ) : (
        <Exception
          type="403"
          linkElement={Link}
        />
      );
    }
  };
}
